#include "RenderManager.h"
#include "..\Engines\SFML2DRenderEngine.h"
#include "..\Define.h"
#include "..\Debug\DebugLog.h"
#ifdef _WINDOWS
	#include <Windows.h>
#endif

RenderManager::RenderManager(void)
{
	m_renderEngine = nullptr;
}

RenderManager::~RenderManager(void)
{
	if (m_renderEngine != nullptr)
	{
		delete m_renderEngine;
		m_renderEngine = nullptr;
	}
}

RenderManager* RenderManager::m_instance = nullptr;

RenderManager& RenderManager::getSingleton()
{
	if (m_instance == nullptr)
		m_instance = new RenderManager;
	return *m_instance;
}

void RenderManager::clean()
{
	if (m_instance != nullptr)
	{
		delete m_instance;
		m_instance = nullptr;
	}
}

void RenderManager::beginRender()
{
	if (m_renderEngine != nullptr)
	{
		m_renderEngine->beginRender();
	}
}

void RenderManager::endRender()
{
	if (m_renderEngine != nullptr)
	{
		m_renderEngine->endRender();
	}
}

void RenderManager::createRenderEngine(RenderEngine* p_renderEngine)
{
	if (m_renderEngine == nullptr)
	{
		m_renderEngine = p_renderEngine;
		m_renderEngine->initialize();
	}
	else
	{
		if (p_renderEngine != nullptr)
		{
			delete p_renderEngine;
			p_renderEngine = nullptr;
		}
		Debug::log("WARNING: Tring to create new Render Engine when one already exists");
	}
}